<!-- 工单信息创建 -->
<template>
	<div style="width: 100%; max-width: 65rem; margin: 1rem auto">
		<h2 style="color: red; text-align: center; padding: 0.5rem">{{ $t('message.orderNewsCreate.pageOrderCreate') }}</h2>

		<div>
			<table>
				<!-- 任务名称、创建时间和结束时间 -->
				<tr>
					<td class="label">{{ $t('message.orderSystem.pageTaskName') }}:</td>
					<td><input type="text" v-model="formData.taskName" /></td>
					<td class="label">{{ $t('message.orderSystem.pageCreateTime') }}:</td>
					<td>{{ formData.creationTime }}</td>
					<td class="label">{{ $t('message.orderSystem.pageEndTimeTable') }}:</td>
					<td><input type="text" v-model="formData.endTime" /></td>
				</tr>

				<!-- 工单状态和创建用户 -->
				<tr>
					<td class="label">{{ $t('message.orderSystem.pageCreatedBy') }}:</td>
					<td>{{ formData.orderStatus }}</td>
					<td class="label">{{ $t('message.orderSystem.pageWorkOrderStatus') }}:</td>
					<td>{{ formData.creator }}</td>
					<td class="label">{{ $t('message.orderSystem.pageDeviceTypeTable') }}:</td>
					<td><input type="text" v-model="formData.deviceType" /></td>
				</tr>

				<!-- 所属电站和所属设备 -->
				<tr>
					<td class="label">{{ $t('message.orderSystem.pageBelongStation') }}:</td>
					<td><input type="text" v-model="formData.powerStation" /></td>
					<td class="label">{{ $t('message.orderSystem.pageBelongDevice') }}:</td>
					<td><input type="text" v-model="formData.equipment" /></td>
					<td class="label">{{ $t('message.orderNewsCreate.pageBelongUser') }}:</td>
					<td><input type="text" v-model="formData.owner" /></td>
				</tr>

				<!-- 问题描述 -->
				<tr>
					<td class="label">{{ $t('message.orderSystem.pageIssueDesc') }}:</td>
					<td colspan="5">
						<textarea v-model="formData.problemDescription" rows="6" cols="90"></textarea>
					</td>
				</tr>

				<!-- 处理过程 -->
				<tr>
					<td class="label">{{ $t('message.orderNewsCreate.pageDealProcess') }}:</td>
					<td colspan="5">
						<textarea v-model="formData.processingSteps" rows="6" cols="90"></textarea>
					</td>
				</tr>

				<!-- 处理图片 -->
				<tr>
					<td class="label">{{ $t('message.orderNewsCreate.pageDealImage') }}:</td>
					<td colspan="5">
						<input type="file" multiple @change="handleFileUpload" />
					</td>
				</tr>

				<!-- 审批意见 -->
				<tr>
					<td class="label">{{ $t('message.orderSystem.pageApprovalComments') }}:</td>
					<td colspan="5">
						<textarea v-model="formData.approvalOpinion" rows="6" cols="90"></textarea>
					</td>
				</tr>
			</table>
		</div>

		<div class="form-actions">
			<el-button type="primary" @click="submitForm">{{ $t('message.orderNewsCreate.pageSubmitForm') }}</el-button>
			<el-button @click="resetForm">{{ $t('message.orderNewsCreate.pageResetForm') }}</el-button>
		</div>
	</div>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs } from 'vue';

export default defineComponent({
	name: 'orderNewsCreate',

	setup() {
		const state = reactive({
			formData: {
				taskName: '',
				endTime: '',
				orderStatus: '上报中',
				creator: 'HKCW',
				creationTime: '2025-05-23 15:48:00',
				deviceType: '',
				powerStation: '',
				equipment: '',
				owner: '',
				problemDescription: '',
				processingSteps: '',
				approvalOpinion: '',
			},
		});

		const submitForm = () => {
			console.log('Submitting:', state.formData);
			// 添加处理逻辑
		};

		const resetForm = () => {
			Object.keys(state.formData).forEach((key) => {
				(state.formData as any)[key] = '';
			});
		};

		const handleFileUpload = (event: Event) => {
			const target = event.target as HTMLInputElement;
			const files = target.files;
			if (files) {
				console.log('Files uploaded:', files);
				// 可以在这里添加上传逻辑或保存到组件状态
			}
		};

		return {
			...toRefs(state),
			submitForm,
			resetForm,
			handleFileUpload,
		};
	},
});
</script>

<style lang="scss" scoped>
.label {
	color: #000;
	text-align: center;
	font-weight: bolder;
}

table {
	width: 100%;
	border-collapse: collapse;
}

td {
	padding: 0.5rem;
	border: 1px solid #000;
}

.form-actions {
	display: flex;
	margin-top: 0.6rem;
	justify-content: center;
}
</style>
